package com.app.micaihu.view.main.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.app.micaihu.R;
import com.app.micaihu.adapter.PagerAdapter.CommonFragmentAdapter;
import com.app.micaihu.app.AppApplication;
import com.app.micaihu.base.BaseOldActivity;
import com.app.micaihu.base.BaseOldFragment;
import com.app.micaihu.configure.Config;
import com.app.utils.stickheaderview.tab.SlidingTabLayout;

import java.util.ArrayList;

/**
 * Created by Guo on 2017/5/22.
 *
 *
 * 视频
 */

public class VideoRankPageFragment extends BaseOldFragment {



    /********
     * 页面控件
     **********/
    private View mContextView;
    private ViewPager mViewpager;

    private String[] titls = {AppApplication.getInstance().getString(R.string.video_rank_comment),
            AppApplication.getInstance().getString(R.string.video_rank_hot),
            AppApplication.getInstance().getString(R.string.video_rank_month)
    };
    /***********
     * 逻辑数据
     ***********/
    private ArrayList<Fragment> fragments = new ArrayList<Fragment>();//新闻页面集合
    private SlidingTabLayout navTab;
    private int position;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (mContextView == null) {
            mContextView = inflater.inflate(R.layout.fragment_gameranking, null);
            mViewpager = (ViewPager) mContextView.findViewById(R.id.mViewPager);
            navTab = (SlidingTabLayout) mContextView.findViewById(R.id.navig_tab);
            initView();
        }

        return mContextView;
    }





    /**
     * 初始化布局
     */
    private void initView() {
        fragments.clear();
//      排行榜分类，1点播榜 2热评榜 3月度榜
        for (int i = 0; i < 3; i++) {
            VideoRankingFragment videoRankingFragment = new VideoRankingFragment();
            Bundle bundle = new Bundle();
            if (i == 0) {
                bundle.putString(Config.Extra.PARAMETER1, "1");
            } else if (i == 1) {
                bundle.putString(Config.Extra.PARAMETER1, "2");
            } else if (i == 2) {
                bundle.putString(Config.Extra.PARAMETER1, "3");
            }

            videoRankingFragment.setArguments(bundle);
            fragments.add(videoRankingFragment);
        }

        CommonFragmentAdapter commonFragmentAdapter = new CommonFragmentAdapter(getChildFragmentManager(), fragments, titls);

        mViewpager.setAdapter(commonFragmentAdapter);
        mViewpager.setOffscreenPageLimit(fragments.size());
        navTab.setViewPager(mViewpager);
        mViewpager.setCurrentItem(0);
        navTab.setTabSelected(0);

    }




}
